package com.faner.controller;

import com.faner.function.GuDan;
import com.faner.source.SpringSourceCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/gu")
@RestController
public class Gu extends SpringSourceCode {


    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/")
    public String home() {
        return "hello gu!";
    }

    @RequestMapping("/{id}")
    String home33(@PathVariable(value = "id", required = true) int id) {
        if (id != 3) return "输入错误！";
        GuDan.refresh();
        return "Hello gudan!";
    }

    @RequestMapping("/re/{id}")
    String home3(@PathVariable(value = "id", required = true) int id) {
        GuDan.reply1(id);
        return "Hello reply!";
    }

    @RequestMapping("/re/{id}/{content}")
    String home33(@PathVariable(value = "id", required = true) int id, @PathVariable(value = "content") String content) {
        GuDan.reply1(id, content);
        return "Hello reply!";
    }

    @RequestMapping("up/{tid}/{times}")
    String up(@PathVariable(value = "tid", required = true) int tid, @PathVariable(value = "times") int times) {
        GuDan.up(tid, times);
        return "点赞成功！";
    }

    @RequestMapping("down/{tid}/{times}")
    String down(@PathVariable(value = "tid", required = true) int tid, @PathVariable(value = "times") int times) {
        GuDan.down(tid, times);
        return "踩成功！";
    }

    @RequestMapping("/er")
    String testerror() throws Exception {
        throw new Exception("eo");
    }
}
